#ifndef __LOG_H_
#define __LOG_H_




#include "stdio.h"
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#define FATAL      1
#define ALARM      2
#define ERROR      3
#define WARN       4
#define INFO       5
#define DEBUG      6

#define DEBUGLEVEL  WARN
 
#define PRESENT_BIT32(x)           (((uint32)((uint32)1<<(x)))) //对应位的值
#define BIT_ON32(m, b)             (((m) & PRESENT_BIT32(b)) != 0)
#define SET_BIT32(m, b)            ((m) |= PRESENT_BIT32(b))
#define CLEAR_BIT32(m, b)          ((m) &= ~PRESENT_BIT32(b))

#define MY_LOG(level, fmt, ...)  do{  \
    if(level <= DEBUGLEVEL){  \
        struct tm temptemp;\
        char timestr[50] = {0};\
        time_t timestamp = time(NULL); \
        localtime_r(&timestamp, &temptemp);\
        asctime_r(&temptemp,timestr);\
        memset(timestr+strlen(timestr)-1, 0, 2);\
        printf("[%s][%s][%d][%s]", __FILE__, __FUNCTION__, __LINE__,timestr); \
        printf(fmt,  ##__VA_ARGS__); \
    }  \
}while(0)

#define MY_ERROR_LOG(fmt, ...)   MY_LOG(ERROR, fmt, ##__VA_ARGS__)




#endif
